//******************************************************************
//******************************************************************
//**********          ANts Peer To Peer Sources        *************
//
// ANts P2P realizes a third generation P2P net. It protects your
// privacy while you are connected and makes you not trackable, hiding
// your identity (ip) and crypting everything you are sending/receiving
// from others.

// Copyright (C) 2004  Roberto Rossi

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

package ants.p2p.query;

import java.net.InetAddress;
import javax.crypto.*;

public class HttpServerInfo extends QueryTuple{
  Object description;
  Object homePage;
  Object ownerId;
  Object ownerIp;
  Object seenOn;

  static final int maxDescriptionLength = 255;

  public HttpServerInfo(String sessionKey, String homePage, String description, String ownerId, String ownerIp, Long seenOn) {
    super(sessionKey);
    this.homePage=homePage;
    this.description=description;
    if(description.length() > HttpServerInfo.maxDescriptionLength)
      description = description.substring(0,HttpServerInfo.maxDescriptionLength-1);
    this.ownerId=ownerId;
    this.ownerIp=ownerIp;
    this.seenOn=seenOn;
  }

  public String getHomePage(){
    if (this.homePage instanceof String)
      return (String)this.homePage;
    else
      return null;
  }

  public String getDescription(){
    if (this.description instanceof String)
      return (String)this.description;
    else
      return null;
  }

  public String getOwnerId(){
    if (this.ownerId instanceof String)
      return (String)this.ownerId;
    else
      return null;
  }

  public String getOwnerIp(){
    if (this.ownerId instanceof String)
      return (String)this.ownerIp;
    else
      return null;
  }

  public Long getSeenOn() {
    if (this.seenOn instanceof Long)
      return (Long)this.seenOn;
    else
      return null;
  }

  public void encrypt(Cipher c) throws Exception {
    this.description = new SealedObject( (String)this.description, c);
    this.homePage = new SealedObject( (String)this.homePage, c);
    //this.ownerId = new SealedObject( (String)this.ownerId, c);
  }

  public void decrypt(Cipher c) throws Exception {
    this.description = (String) ( (SealedObject)this.description).getObject(c);
    this.homePage = (String) ( (SealedObject)this.homePage).getObject(c);
    //this.ownerId = (String) ( (SealedObject)this.ownerId).getObject(c);
  }

  public boolean equals(Object o){
    if(o instanceof HttpServerInfo){
      HttpServerInfo so = (HttpServerInfo)o;
      return this.ownerId.equals(so.getOwnerId()) &&
          this.getHomePage().equals(so.getHomePage());
    }else{
      return this == o;
    }
  }

  public String toString(){
    return ji.JI.i("Owner")+": "+this.getOwnerId().substring(0,10)+"   "+ji.JI.i("Page")+": "+this.getHomePage() + "   " + this.getDescription();
  }
}
